#!/usr/bin/bash

#服务器ip
HOST_IP="10.7.20.60"

#用户&密码
USERNAME="incloud"
PASSWD="Inspur2!"

# 获取token地址
TOKEN_URI="https://$HOST_IP/auth/realms/master/protocol/openid-connect/token"
# get token
res=$(curl -sk -X POST "$TOKEN_URI" \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode "username=$USERNAME" \
    --data-urlencode "password=$PASSWD" \
    --data-urlencode 'grant_type=password' \
    --data-urlencode 'client_id=admin-cli' | jq -r .access_token)

echo "access token is :  $res"



#这里ibase访问地址不同环境有所不同，分a,b两种情况
# 绑定权限:a
curl -X POST http://$HOST_IP:30079/ibase/v1/auth/tokens \
    -H "Authorization: Bearer $res" \
    -H "Content-Type: application/json" \
    -d "{}"

# 绑定权限:b
# 正式环境 可能30079端口不开放，换下面这个
curl -X POST https://$HOST_IP/api/ibase/v1/auth/tokens \
    -H "Authorization: Bearer $res" \
    -H "Content-Type: application/json" \
    -d "{}"
